package me.zhujin.java.learnjava.myserver.servlet;

import me.zhujin.java.learnjava.myserver.MyRequest;
import me.zhujin.java.learnjava.myserver.MyResponse;
import me.zhujin.java.learnjava.myserver.MyServlet;
import me.zhujin.java.learnjava.myserver.util.ScriptUtil;

import java.io.FileNotFoundException;

/**
 * Created by zhujin on 10/24/16.
 * blog:www.zhujin.me
 * email: zhujin.nova@gmail.com
 */
public class HTMLServlet extends MyServlet {

    @Override
    protected void doPost(MyRequest request, MyResponse response) throws Exception {
        doGet(request, response);
    }

    @Override
    protected void doGet(MyRequest request, MyResponse response) throws Exception {
        String url = request.getUrl();
        try {
            Object res = ScriptUtil.getDefalutHTMLBody(url);
            if (res == null) {
                flush404(response);
                return;
            }
            response.printLn(res.toString());
        } catch (FileNotFoundException e) {
            flush404(response);
        }
    }


}
